package com.lys.blog.controller;

import com.lys.blog.dao.pojo.Tag;
import com.lys.blog.service.TagService;
import com.lys.blog.vo.Result;
import com.lys.blog.vo.params.PageParams;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("tags")
public class TagsController {
    @Autowired
    private TagService tagService;

    @GetMapping("hot")
    public Result hot() {
        int limit = 6;
        return tagService.hots(limit);
    }
    @GetMapping
    public Result findAll() {
        return tagService.findAll();
    }

    @PostMapping
    public Result listByPage(@RequestBody PageParams page) {
        return tagService.listByPage(page);
    }

    @GetMapping("detail")
    public Result tagsDetails() {
        return tagService.tagsDetails();
    }

    @GetMapping("detail/{id}")
    public Result tagsDetailsById(@PathVariable Long id) {
        return tagService.tagsDetailsById(id);
    }

    @PostMapping("add")
    public Result addTags(@RequestBody Tag tag) {
        return tagService.addTags(tag);
    }

    /*@PostMapping("delete/{id}")
    public Result deleteTags(@PathVariable Long id) {
        return tagService.deleteTags(id);
    }*/

    /*@PostMapping("delete")
    public Result deleteTags(@RequestParam Long id) {
        return tagService.deleteTags(id);
    }*/
    @PostMapping(value = "delete")
    public Result deleteTags(@RequestBody  Tag tag) {
        System.out.println(tag.getId());
        return tagService.deleteTags(tag.getId());
    }

    /*@PostMapping("delete")
    public Result deleteTags(@RequestBody Integer id) {
        System.out.println(id);
        return Result.success(null);
    }*/

    @PostMapping(value = "modify")
    public Result modifyTags(@RequestBody Tag tag) {
        return tagService.modifyTags(tag);
    }

    @GetMapping(value = "demo")
    public Result demo() {
        System.out.println(2);
        int a=8;
        int c=2222;
        System.out.println(a+c);
        return Result.success(a+c);
    }




}
